### PACKAGE PREAMBLE ###

# Create a vector of package names
packages <- c("dplyr", "ggplot2", "tidyr", "tidyverse", "data.table", "readxl", "foreign", "devtools", "fixest", "sandwich", "modelsummary", "kableExtra")

installed_packages <- packages %in% rownames(installed.packages())
if (any(installed_packages == FALSE)) {
  install.packages(packages[!installed_packages])
}

# Packages loading
invisible(lapply(packages, library, character.only = TRUE))
rm(packages, installed_packages)

options(modelsummary_format_numeric_latex = "plain")
f <- function(x) format(x, digits = 3, nsmall = 2, scientific = FALSE)

getwd()
setwd(dir = "/Users/jmc4qg/The Lab Dropbox/Jonathan Colmer/ShotSpotter_env/Journal_submissions/ReStat/Replication Folder")

mydata_ES <- read.dta("Analysis Data/NIBRS_analysis_ES.dta")

DiDiT_ES<- feols(homicide_pc~ i(CT_rel, tMean, -1) + i(CT_rel, prec, -1) | ori_sample_month+ORI[tMean]+sample_month[tMean]+ORI[prec]+sample_month[prec]+week + dow, data=mydata_ES)
summary(DiDiT_ES, cluster="STATE")
coef_table_ES <- coeftable(DiDiT_ES, cluster="STATE")

write.csv(coef_table_ES, "Figures and Tables/Figure_3/Figure_3_data.csv")
